#/bin/bash


HOME_DIR=$(cd $(dirname $0);cd ../;pwd)
cd script
pwd
architecture=${1:-hybrid}
echo $architecture
export GS_PASSWORD='Gauss!23'
#export STANDBYHOSTS=127.0.0.1

export GAUSSHOME=/opt/openGauss
export GAUSSLOG=/opt/data/gausslog
export PGDATA=/opt/data/openGauss
export PGHOST=/opt/data/tmp

function generate_xml() {
    export PRIMARYHOST="172.11.0.2"
    export STANDBYHOSTS="172.11.0.3,172.11.0.4"
    export PRIMARYNAME=db-opengauss-01
    export STANDBYNAMES=db-opengauss-02,db-opengauss-03
    echo "python3 generateconf.py --primary-host=${PRIMARYHOST} --standby-host=${STANDBYHOSTS} --primary-hostname=${PRIMARYNAME} --standby-hostname=${STANDBYNAMES}"
    python3 generateconf.py \
        --primary-host=${PRIMARYHOST} \
        --standby-host=${STANDBYHOSTS} \
        --primary-hostname=${PRIMARYNAME} \
        --standby-hostname=${STANDBYNAMES}
    if [ ! -f "cluster.xml" ]; then
        echo "generate cluster xml file failed."
        exit 1
    fi
    echo "generate mixed cluster xml file success."
    #cat cluster.xml
}

function generate_mixed_xml() {
    export PRIMARYHOST=172.11.0.4
    export STANDBYHOSTS="172.11.0.5,172.11.0.6"
    export PRIMARYNAME=db-opengauss-03
    export STANDBYNAMES=db-opengauss-04,db-opengauss-05
    export CMSHOSTS="172.11.0.2,172.11.0.3,172.11.0.4"
    export CMSNAMES=db-opengauss-01,db-opengauss-02,db-opengauss-03
    echo "python3 generateconf.py --primary-host=${PRIMARYHOST} --standby-host=${STANDBYHOSTS} --primary-hostname=${PRIMARYNAME} --standby-hostname=${STANDBYNAMES}"
    python3 generateconf.py \
        --primary-host=${PRIMARYHOST} \
        --standby-host=${STANDBYHOSTS} \
        --primary-hostname=${PRIMARYNAME} \
        --standby-hostname=${STANDBYNAMES} \
        --cms-host=${CMSHOSTS} \
        --cms-hostname=${CMSNAMES} 
    if [ ! -f "cluster.xml" ]; then
        echo "generate cluster xml file failed."
        exit 1
    fi
    echo "generate mixed cluster xml file success."
    #cat cluster.xml
}
function generate_split_xml() {
    export PRIMARYHOST=172.11.0.5
    export STANDBYHOSTS="172.11.0.6,172.11.0.7"
    export PRIMARYNAME=db-opengauss-04
    export STANDBYNAMES=db-opengauss-05,db-opengauss-06
    export CMSHOSTS="172.11.0.2,172.11.0.3,172.11.0.4"
    export CMSNAMES=db-opengauss-01,db-opengauss-02,db-opengauss-03
    echo "python3 generateconf.py --primary-host=${PRIMARYHOST} --standby-host=${STANDBYHOSTS} --primary-hostname=${PRIMARYNAME} --standby-hostname=${STANDBYNAMES}"
    python3 generateconf.py \
        --primary-host=${PRIMARYHOST} \
        --standby-host=${STANDBYHOSTS} \
        --primary-hostname=${PRIMARYNAME} \
        --standby-hostname=${STANDBYNAMES} \
        --cms-host=${CMSHOSTS} \
        --cms-hostname=${CMSNAMES} 
    if [ ! -f "cluster.xml" ]; then
        echo "generate cluster xml file failed."
        exit 1
    fi
    echo "generate split cluster xml file success."
}

generate_xml